﻿using System;
using UnityEngine;

namespace UnityStandardAssets.ImageEffects
{
	// Token: 0x02000600 RID: 1536
	[RequireComponent(typeof(Camera))]
	[ExecuteInEditMode]
	[AddComponentMenu("Image Effects/Camera/Vignette and Chromatic Aberration")]
	public class VignetteAndChromaticAberration : PostEffectsBase
	{
		// Token: 0x06001E0A RID: 7690 RVA: 0x0006E668 File Offset: 0x0006C868
		public override bool CheckResources()
		{
			base.CheckSupport(false);
			this.m_VignetteMaterial = base.CheckShaderAndCreateMaterial(this.vignetteShader, this.m_VignetteMaterial);
			this.m_SeparableBlurMaterial = base.CheckShaderAndCreateMaterial(this.separableBlurShader, this.m_SeparableBlurMaterial);
			this.m_ChromAberrationMaterial = base.CheckShaderAndCreateMaterial(this.chromAberrationShader, this.m_ChromAberrationMaterial);
			if (!this.isSupported)
			{
				base.ReportAutoDisable();
			}
			return this.isSupported;
		}

		// Token: 0x06001E0B RID: 7691 RVA: 0x0006E6DC File Offset: 0x0006C8DC
		public void OnRenderImage(RenderTexture source, RenderTexture destination)
		{
			if (!this.CheckResources())
			{
				Graphics.Blit(source, destination);
				return;
			}
			int width = source.width;
			int height = source.height;
			object obj = Mathf.Abs(this.blur) > 0f || Mathf.Abs(this.intensity) > 0f;
			float num = 1f * (float)width / (1f * (float)height);
			RenderTexture renderTexture = null;
			RenderTexture renderTexture2 = null;
			if (obj != null)
			{
				renderTexture = RenderTexture.GetTemporary(width, height, 0, source.format);
				this.m_VignetteMaterial.SetFloat("_Intensity", 1f / (1f - this.intensity) - 1f);
				this.m_VignetteMaterial.SetFloat("_Blur", 1f / (1f - this.blur) - 1f);
				this.m_VignetteMaterial.SetTexture("_VignetteTex", renderTexture2);
				Graphics.Blit(source, renderTexture, this.m_VignetteMaterial, 0);
			}
			this.m_ChromAberrationMaterial.SetFloat("_ChromaticAberration", this.chromaticAberration);
			this.m_ChromAberrationMaterial.SetFloat("_AxialAberration", this.axialAberration);
			this.m_ChromAberrationMaterial.SetVector("_BlurDistance", new Vector2(-this.blurDistance, this.blurDistance));
			this.m_ChromAberrationMaterial.SetFloat("_Luminance", 1f / Mathf.Max(Mathf.Epsilon, this.luminanceDependency));
			if (obj != null)
			{
				renderTexture.wrapMode = TextureWrapMode.Clamp;
			}
			else
			{
				source.wrapMode = TextureWrapMode.Clamp;
			}
			Graphics.Blit((obj == null) ? source : renderTexture, destination, this.m_ChromAberrationMaterial, (this.mode != VignetteAndChromaticAberration.AberrationMode.Advanced) ? 1 : 2);
			RenderTexture.ReleaseTemporary(renderTexture);
			RenderTexture.ReleaseTemporary(renderTexture2);
		}

		// Token: 0x06001E0C RID: 7692 RVA: 0x00012FC4 File Offset: 0x000111C4
		public void OnEnable()
		{
			this.blur = 0f;
			this.blurDistance = 0f;
			this.chromaticAberration = 0f;
		}

		// Token: 0x0400182F RID: 6191
		public VignetteAndChromaticAberration.AberrationMode mode;

		// Token: 0x04001830 RID: 6192
		public float intensity = 0.036f;

		// Token: 0x04001831 RID: 6193
		public float chromaticAberration = 0.2f;

		// Token: 0x04001832 RID: 6194
		public float axialAberration = 0.5f;

		// Token: 0x04001833 RID: 6195
		public float blur;

		// Token: 0x04001834 RID: 6196
		public float blurSpread = 0.75f;

		// Token: 0x04001835 RID: 6197
		public float luminanceDependency = 0.25f;

		// Token: 0x04001836 RID: 6198
		public float blurDistance = 2.5f;

		// Token: 0x04001837 RID: 6199
		public Shader vignetteShader;

		// Token: 0x04001838 RID: 6200
		public Shader separableBlurShader;

		// Token: 0x04001839 RID: 6201
		public Shader chromAberrationShader;

		// Token: 0x0400183A RID: 6202
		public Material m_VignetteMaterial;

		// Token: 0x0400183B RID: 6203
		public Material m_SeparableBlurMaterial;

		// Token: 0x0400183C RID: 6204
		public Material m_ChromAberrationMaterial;

		// Token: 0x02000601 RID: 1537
		public enum AberrationMode
		{
			// Token: 0x0400183E RID: 6206
			Simple,
			// Token: 0x0400183F RID: 6207
			Advanced
		}
	}
}
